import javax.swing.plaf.synth.SynthUI;
import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;

class Student implements Comparable<Student>{
    public int age;
    public String name;

    //compareTo只是比较对象的大小关系，返回值为正数，负数，0 （两个对象的差值）
    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name);
    }


}

class AgeComparator implements Comparator<Student> {
    public int compare(Student o1,Student o2) {
        return o1.age - o2.age;
    }
}

class NameComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}

public class Test {
    public static void main(String[] args) {
        Student s1 = new Student();
        s1.age = 10;
        s1.name = "zhangsan";
        Student s2 = new Student();
        s2.age = 9;
        s2.name = "zhangsan";

        AgeComparator ageComparator = new AgeComparator();
        System.out.println(ageComparator.compare(s1,s2));

        NameComparator nameComparator = new NameComparator();
        System.out.println(nameComparator.compare(s1, s2));
    }

    public static void main2(String[] args) {
        Student s1 = new Student();
        s1.age = 10;
        s1.name = "zhangsan";
        Student s2 = new Student();
        s2.age = 9;
        s2.name = "zhangsan";
        System.out.println(s1.equals(s2));
        //System.out.println(s1.compareTo(s2));
    }

    public static void main1(String[] args) {
        //PriorityQueue中防止的元素必须能够比较大小，不能呢插入无法比较大小的对象，否则会抛出ClassCaseException异常
        //不能插入null对象，会抛NullPointerException异常
        //没有容量限制，可以插入任意多个元素，其内部可以自动扩容
        //插入和删除元素的时间复杂度为O(logN)
        //PriorityQueue底层使用了堆数据结构
        //PriorityQueue默认情况下是小堆(最先取到的是最小的数)

        //默认分配了一个长度为11的queue数组
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();

//        Queue<Integer> priorityQueue1 = new PriorityQueue<>();
//        priorityQueue1.offer(11);
//        priorityQueue1.offer(2);
//        priorityQueue1.offer(3);
//        System.out.println(priorityQueue1.poll());//2
//        System.out.println(priorityQueue1.poll());//3
//        System.out.println(priorityQueue1.poll());//11


        Queue<Student> priorityQueue2 = new PriorityQueue<>();
        priorityQueue2.offer(new Student());
        //priorityQueue2.offer(null);/**/
    }
}
